{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "c2de5d03-0a10-42c1-9ae3-d8ba27ce0694",
   "metadata": {},
   "outputs": [],
   "source": [
    "def add(a, b):\n",
    "    return a + b"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "160e4852-db70-4ae7-b773-5e9ccf83f775",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "33"
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "add(10, 20) + 3"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "c220b1c6-63fe-450e-aee3-f43d9e9a6ecf",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'正数'"
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "x = 1\n",
    "\n",
    "\"正数\" if x > 0 else \"零或负数\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "id": "e9e824d8-ae2c-4146-8787-5ba8a0a36046",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'正数'"
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "if x > 0:\n",
    "    result = \"正数\"\n",
    "else:\n",
    "    result = \"零或负数\"\n",
    "\n",
    "result"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "2ca26045-83ea-4da8-9664-9a5f62bf163b",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "id": "ea9ce51c-20bd-4a6e-9846-ca9ef164450f",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "零或负数\n"
     ]
    }
   ],
   "source": [
    "x = -1\n",
    "\n",
    "y = \"正数\" if x > 0 else \"零或负数\"\n",
    "print(y)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "c870e148-cf38-492f-80a7-e9ff9411b8b8",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "41693748-2142-43e8-a2f7-272cf60b6a8d",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'肥胖'"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "weight = 90\n",
    "height = 1.72\n",
    "bmi = weight / (height**2)\n",
    "\n",
    "'过轻' if bmi < 18.5 else (\n",
    "    '正常' if bmi < 24 else ( \n",
    "        '过重' if bmi < 28 else '肥胖') )"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "d51acc2e-13a6-4e38-9546-b4a28128c4f1",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 30,
   "id": "397058ab-d4cb-4fda-b913-944924bb40b9",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "BMI: 30.42, 肥胖\n"
     ]
    }
   ],
   "source": [
    "bmi = weight / (height**2)\n",
    "\n",
    "if bmi < 18.5:\n",
    "    bmi_kind = '过轻'\n",
    "elif bmi < 24:\n",
    "    bmi_kind = '正常'\n",
    "elif bmi < 28:\n",
    "    bmi_kind = '过重'\n",
    "else:\n",
    "    bmi_kind = '肥胖'\n",
    "\n",
    "print(f\"BMI: {bmi:0.2f}, {bmi_kind}\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "1af70a31-ff48-45a7-8483-3e115d432058",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "a1e53b6f-4f6b-4ed6-965b-f5b0c3208815",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'肥胖'"
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "(('过轻' if bmi < 18.5 else '正常') \n",
    "     if bmi < 24 else ('过重' if bmi < 28 else  '肥胖'))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 31,
   "id": "c9209265-0598-4d98-9c0c-613ea4ed4f93",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "BMI: 30.42, 肥胖\n"
     ]
    }
   ],
   "source": [
    "bmi = weight / (height**2)\n",
    "\n",
    "if bmi < 24:\n",
    "    if bmi < 18.5:\n",
    "        bmi_kind = '过轻'\n",
    "    else:\n",
    "        bmi_kind = '正常'    \n",
    "else:\n",
    "    if bmi < 28:\n",
    "        bmi_kind = '过重'\n",
    "    else:\n",
    "        bmi_kind = '肥胖'\n",
    "\n",
    "print(f\"BMI: {bmi:0.2f}, {bmi_kind}\")"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.10.12"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
